package com.base.themvx.utils

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asCoroutineDispatcher
import java.util.concurrent.ExecutorService

/**
 ******************(^_^)***********************<br>
 * Author: fee(QQ/WeiXin:1176610771)<br>
 * <P>DESC:
 * 各协程　Scope
 * </p>
 * ******************(^_^)***********************
 */
object XCoroutineScope {

    /**
     * 主线程中的　CoroutineScope
     */
    val mainCoroutineScope by lazy {
        CoroutineScope(Dispatchers.Main)
    }

    /**
     * 需要外部指定线程执行器
     */
    var mExecutor: ExecutorService? = null

    val ioCoroutineScope by lazy {
        val asCoroutineDispatcher = mExecutor?.asCoroutineDispatcher() ?: return@lazy null
        CoroutineScope(asCoroutineDispatcher)
    }

    fun execute(task: Runnable){
        mExecutor?.execute(task)
    }
}